#include "imageviewer.h"

extern Image myImage;
extern MyWindow *win;
extern int toolSize;

// undoAdd() adds stuff on top of the undo list/buff/stack/ wtf container type
void undoAdd();

// undoDel() removes stuff from the undo and puts it back into the image data
// still doesn't clean up after itself, damn lazy code!
void undoDel();

/*FLTK call back funtion definitions.  These functions are executed based on what menu options the user chooses from the interface  */
static void cb_Open(Fl_Menu_*, void*) {
  
    myImage.ReadFile();
   
}
static void cb_Save(Fl_Menu_*, void*) {
	myImage.WriteFile();
}

static void cb_Exit(Fl_Menu_*, void*) {
	exit(1);
}

static void cb_Grayscale(Fl_Menu_*, void*) {
	undoAdd();
	myImage.grayscale();
}

static void cb_RedChannel(Fl_Menu_*, void*) {
	undoAdd();
	myImage.redChannel();
}

static void cb_GreenChannel(Fl_Menu_*, void*) {
	undoAdd();
	myImage.greenChannel();
}

static void cb_BlueChannel(Fl_Menu_*, void*) {
	undoAdd();
	myImage.blueChannel();
}

static void cb_undo(Fl_Menu_*, void*) {
	undoDel();
	win->draw();
	win->redraw();
}

static void cb_MirrorX(Fl_Menu_*, void*) {
	undoAdd();
	myImage.mirrorX();
}

static void cb_MirrorY(Fl_Menu_*, void*) {
	undoAdd();
	myImage.mirrorY();
}

static void cb_Rotate(Fl_Menu_*, void*) {
	undoAdd();
	myImage.rotate(45.0);
}

static void cb_Redraw(Fl_Menu_*, void*) {
	win->resize(30,30,myImage.nx,myImage.ny);
}

static void cb_Brighten(Fl_Widget* w, void*) {
	undoAdd();
	int value = ((Fl_Valuator*)w)->value();
	std::cout << "Bright Slider value: " << value << "\n";
	myImage.modImage(value,value,value);
	win->redraw();
}

static void cb_Darken(Fl_Menu_*, void*) {
	undoAdd();
	myImage.darken();
}

static void cb_Posterize(Fl_Menu_*, void*) {
	undoAdd();
	myImage.posterize();
}
static void cb_SliderRed(Fl_Widget *w, void*) {
undoAdd();
	int value = ((Fl_Valuator*)w)->value();
	std::cout << "Slider value: " << value << "\n";
	myImage.modImage(value,0,0);
	win->redraw();
}
static void cb_SliderGreen(Fl_Widget *w, void*) {
undoAdd();
	int value = ((Fl_Valuator*)w)->value();
	std::cout << "Slider value: " << value << "\n";
	myImage.modImage(0,value,0);
	win->redraw();
}
static void cb_SliderBlue(Fl_Widget *w, void*) {
undoAdd();
	int value = ((Fl_Valuator*)w)->value();
	std::cout << "Slider value: " << value << "\n";
	myImage.modImage(0,0,value);
	win->redraw();
}
static void cb_LineSize(Fl_Widget *w, void*) {
	int value = ((Fl_Valuator*)w)->value();
	toolSize = value;
}
static void cb_Zoom(Fl_Menu_*, void*) {
	std::cout << "ZOOM";
	undoAdd();
	
	
}


/*************END FLTK call back functions***********************************/